// https://github.com/jjonline/calendar.js/
import { default as calendar } from "npm:js-calendar-converter";

function formatDate(y: number, m: number, d: number): string {
    const yyyy = y.toString().padStart(4, "0");
    const mm = m.toString().padStart(2, "0");
    const dd = d.toString().padStart(2, "0");
    return `${yyyy}-${mm}-${dd}`;
}

const file = await Deno.create("nugine_solutions/data/lunar11.txt");
const writer = file.writable.getWriter();

for (let y = 1800; y <= 2200; y++) {
    const date = calendar.lunar2solar(y, 1, 1);
    if (!date.date) {
        continue;
    }
    const solarDate = formatDate(date.cYear, date.cMonth, date.cDay);
    const text = `${y}:${solarDate}`;
    await writer.write(new TextEncoder().encode(text + "\n"));
}

await writer.close();
